{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "134e7f9d",
   "metadata": {},
   "source": [
    "# Physics 1: Lagrangian neural network"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "66865edb",
   "metadata": {},
   "outputs": [],
   "source": [
    "from kan import *\n",
    "from kan.utils import batch_jacobian, batch_hessian\n",
    "\n",
    "torch.use_deterministic_algorithms(True)\n",
    "torch.set_default_dtype(torch.float64)\n",
    "\n",
    "seed = 0\n",
    "torch.manual_seed(seed)\n",
    "\n",
    "#example = 'harmonic_oscillator'\n",
    "#example = 'single_pendulum'\n",
    "example = 'relativistic_mass'\n",
    "\n",
    "# three examples: harmonic oscillator, single pendulum, double pendulum\n",
    "\n",
    "# dimension of q\n",
    "# Lagrangian: (q, qd) -> (qdd)\n",
    "\n",
    "if example == 'harmonic_oscillator':\n",
    "    n_sample = 1000\n",
    "    # harmonic oscillator\n",
    "    d = 1\n",
    "    q = torch.rand(size=(n_sample,1)) * 4 - 2\n",
    "    qd = torch.rand(size=(n_sample,1)) * 4 - 2\n",
    "    qdd = - q\n",
    "    x = torch.cat([q, qd], dim=1)\n",
    "    \n",
    "if example == 'single_pendulum':\n",
    "    n_sample = 1000\n",
    "    # harmonic oscillator\n",
    "    d = 1\n",
    "    q = torch.rand(size=(n_sample,1)) * 4 - 2\n",
    "    qd = torch.rand(size=(n_sample,1)) * 4 - 2\n",
    "    qdd = - torch.sin(q)\n",
    "    x = torch.cat([q, qd], dim=1)\n",
    "    \n",
    "if example == 'relativistic_mass':\n",
    "    n_sample = 10000\n",
    "    # harmonic oscillator\n",
    "    d = 1\n",
    "    q = torch.rand(size=(n_sample,1)) * 4 - 2\n",
    "    #qd = torch.rand(size=(n_sample,1)) * 1.998 - 0.999\n",
    "    #qd = 0.95 + torch.rand(size=(n_sample,1)) * 0.05\n",
    "    qd = torch.rand(size=(n_sample,1)) * 2 - 1\n",
    "    qdd = (1 - qd**2)**(3/2)\n",
    "    x = torch.cat([q, qd], dim=1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "ec549451",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saving model version 0.1\n"
     ]
    }
   ],
   "source": [
    "from kan.compiler import kanpiler\n",
    "from sympy import *\n",
    "\n",
    "input_variables = symbol_x, symbol_vx = symbols('x v_x')\n",
    "expr = symbol_vx ** 2\n",
    "model = kanpiler(input_variables, expr, grid=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "f9930812",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAACuCAYAAAD6ZEDcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAASgklEQVR4nO3de3BU5f3H8c/ZEGBjUkJiuCiKSQgoNyWigKZ2LMiK6c3iOPVHrYzgWFrBf0r/AMc6ttqp8kcyeMGOMw7gwLQ2jhTCNN6LhNQb4A2omFSYIBBCWEhMyGX3+f3xsCThEsCc3XM2vF8zTGJ2N/sNzpMP3/NcjmOMMQIAwEUBrwsAAPQ9hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHX9vC4ASAbGGB0+fFhNTU1KT09Xdna2HMfxuizAt+hcgB6Ew2GVlpaqoKBAOTk5ys3NVU5OjgoKClRaWqpwOOx1iYAvOdwsDDiziooKzZ49W83NzZJs9xIT61rS0tJUVlamUCjkSY2AXxEuwBlUVFSouLhYxhhFo9GzPi8QCMhxHJWXlxMwQBeEC3CKcDisESNGqKWlpcdgiQkEAgoGg6qtrVVmZmb8CwSSAHMuwClWrlyp5ubm8woWSYpGo2pubtaqVaviXBmQPOhcgC6MMSooKFBNTY0uZGg4jq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CQ4zh69dVXGVDoUxgHyY9w8aFQKKTy8nIFg0E5jnNamx/7WjAY1MaNGzVz5kyPKgXih3GQ3AgXnwqFQqqtrVVJSYny8vK6PZaXl6eSkhLt27ePAYU+jXGQvJhzSQLGGDU0NKixsVEZGRnKyspi0hIXHcZBciFcAACu47IYAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1/w+t/uNoMzLGkwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 500x200 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model.get_act(x)\n",
    "model.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "74a1fb02",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saving model version 0.2\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAACuCAYAAAD6ZEDcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAUf0lEQVR4nO3de3TU5Z3H8c8zucDkQm4MhJAEyNWigKQiKqmeFiQqbrcunp61rqsutF23hf1n3T+gx+26a/fU+kdSWkVPz+kqbe1uF46ughutWBGCeEFURAQSIDMhF3KZXEhCMjPP/hGYEkBE+M0l4f36x0MyM79v5Dz58H2e5/f8jLXWCgAAB7liXQAAYPwhXAAAjiNcAACOI1wAAI4jXAAAjiNcAACOI1wAAI4jXAAAjiNcAACOI1wAAI4jXAAAjiNcAACOI1wAAI4jXAAAjkuMdQHAWGCtVUdHh/r6+pSWlqacnBwZY2JdFhC36FyAC/D7/aqpqVFpaak8Ho9mzZolj8ej0tJS1dTUyO/3x7pEIC4ZHhYGnF9tba2WL1+u/v5+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wAQA4jnABADiOcAEAOI5wAQA4jnABADiOcAEAOI5wAQA4jnABADiOcAEAOO7/AX8dLuaR/xUgAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 500x200 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model.perturb(mode='best', mag=0.1)\n",
    "model.get_act(x)\n",
    "model.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "fd0d2987",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "| loss: 5.03e-05 |: 100%|███████████████████████████████████████████| 20/20 [02:59<00:00,  8.99s/it]\n"
     ]
    }
   ],
   "source": [
    "from kan import *\n",
    "from kan.utils import batch_jacobian, create_dataset_from_data\n",
    "import numpy as np\n",
    "\n",
    "torch.use_deterministic_algorithms(True)\n",
    "\n",
    "def closure():\n",
    "    \n",
    "    global loss\n",
    "    optimizer.zero_grad()\n",
    "    \n",
    "    jacobian = batch_jacobian(model, x, create_graph=True)\n",
    "    hessian = batch_hessian(model, x, create_graph=True)\n",
    "    Lqdqd = hessian[:,d:,d:]\n",
    "    Lq = jacobian[:,:d]\n",
    "    Lqqd = hessian[:,d:,:d]\n",
    "\n",
    "    Lqqd_qd_prod = torch.einsum('ijk,ik->ij', Lqqd, qd)\n",
    "\n",
    "    qdd_pred = torch.einsum('ijk,ik->ij', torch.linalg.inv(Lqdqd), Lq - Lqqd_qd_prod)\n",
    "    loss = torch.mean((qdd - qdd_pred)**2)\n",
    "\n",
    "    loss.backward()\n",
    "    return loss\n",
    "\n",
    "steps = 20\n",
    "log = 1\n",
    "optimizer = LBFGS(model.parameters(), lr=1, history_size=10, line_search_fn=\"strong_wolfe\", tolerance_grad=1e-32, tolerance_change=1e-32, tolerance_ys=1e-32)\n",
    "#optimizer = torch.optim.Adam(params, lr=1e-2)\n",
    "pbar = tqdm(range(steps), desc='description', ncols=100)\n",
    "\n",
    "\n",
    "for _ in pbar:\n",
    "    \n",
    "    # update grid\n",
    "    if _ < 5 and _ % 20 == 0:\n",
    "        model.update_grid(x)\n",
    "            \n",
    "    optimizer.step(closure)\n",
    "    \n",
    "    if _ % log == 0:\n",
    "        pbar.set_description(\"| loss: %.2e |\" % loss.cpu().detach().numpy())\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "id": "782f818f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAACuCAYAAAD6ZEDcAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAYiUlEQVR4nO3dWXBc1Z0G8O+01K1e1Yska5ctybIheAGxGLCzjRkrGdfUVEp+GPCQpUJCUWP8xkNM4kpRlVQlxYOEk+CkkgeWKkil5CmK2BNlhjABLzhsxhgTCPLSi6213ft+75mHttpqLC/g2923W9+vylVGUkt/2xx9+p9z7jlCSilBRESkIUOlCyAiotrDcCEiIs0xXIiISHMMFyIi0hzDhYiINMdwISIizTFciIhIcwwXIiLSHMOFiIg0x3AhIiLNMVyIiEhzDBciItIcw4WIiDTHcCEiIs3VV7oAomogpcTc3BxisRjsdjuampoghKh0WUS6xc6F6CpCoRBGR0cxMDCAlpYW9Pb2oqWlBQMDAxgdHUUoFKp0iUS6JHhZGNHixsfHMTw8jEQiASDfvcyb71qsVivGxsYwNDRUkRqJ9IrhQrSI8fFxbN26FVJKqKp6xY8zGAwQQmD//v0MGKIFGC5EnxIKhdDV1YVkMnnVYJlnMBhgsVjg9/vhcrlKXyBRFeCaC9GnPPPMM0gkEtcVLACgqioSiQSeffbZEldGVD3YuRAtIKXEwMAATp06hc8yNIQQ6Ovrwz/+8Q/uIiMCw4WoyOzsLFpaWm7o9U1NTRpWRFSdOC1GtEAsFruh10ej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SHMOFiIg0x3AhIiLNMVyIiEhzDBciItIcw4WIiDTHcCEiIs0xXIiISHMMFyIi0hzDhYiINMdwISIizTFciIhIcwwXIiLS3P8Dh3IFDDpuFuQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 500x200 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "ad876b9d",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/6j/b6y80djd4nb5hl73rv3sv8y80000gn/T/ipykernel_24271/2849209031.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mauto_symbolic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/Desktop/2022/research/code/pykan/kan/MultKAN.py\u001b[0m in \u001b[0;36mauto_symbolic\u001b[0;34m(self, a_range, b_range, lib, verbose)\u001b[0m\n\u001b[1;32m   1402\u001b[0m                         \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf'fixing ({l},{i},{j}) with 0'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1403\u001b[0m                     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1404\u001b[0;31m                         \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mr2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msuggest_symbolic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0ma_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mb_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlib\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlib\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1405\u001b[0m                         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfix_symbolic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mverbose\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlog_history\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1406\u001b[0m                         \u001b[0;32mif\u001b[0m \u001b[0mverbose\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/Desktop/2022/research/code/pykan/kan/MultKAN.py\u001b[0m in \u001b[0;36msuggest_symbolic\u001b[0;34m(self, l, i, j, a_range, b_range, lib, topk, verbose, r2_loss_fun, c_loss_fun, weight_simple)\u001b[0m\n\u001b[1;32m   1332\u001b[0m         \u001b[0;31m# getting r2 and complexities\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1333\u001b[0m         \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontent\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msymbolic_lib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1334\u001b[0;31m             \u001b[0mr2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfix_symbolic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ml\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0ma_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mb_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlog_history\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1335\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mr2\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m1e8\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# zero function\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1336\u001b[0m                 \u001b[0mr2s\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1e8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/Desktop/2022/research/code/pykan/kan/MultKAN.py\u001b[0m in \u001b[0;36mfix_symbolic\u001b[0;34m(self, l, i, j, fun_name, fit_params_bool, a_range, b_range, verbose, random, log_history)\u001b[0m\n\u001b[1;32m    488\u001b[0m             \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mspline_postacts\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ml\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    489\u001b[0m             \u001b[0;31m#y = self.postacts[l][:, j, i]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 490\u001b[0;31m             \u001b[0mr2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbolic_fun\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ml\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfix_symbolic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfun_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0ma_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mb_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    491\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mmask\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    492\u001b[0m                 \u001b[0mr2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;36m1e8\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/Desktop/2022/research/code/pykan/kan/Symbolic_KANLayer.py\u001b[0m in \u001b[0;36mfix_symbolic\u001b[0;34m(self, i, j, fun_name, x, y, random, a_range, b_range, verbose)\u001b[0m\n\u001b[1;32m    229\u001b[0m             \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    230\u001b[0m                 \u001b[0;31m#initialize from x & y and fun\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 231\u001b[0;31m                 \u001b[0mparams\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mr2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfit_params\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mfun\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0ma_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_range\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mb_range\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    232\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfuns\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    233\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfuns_avoid_singularity\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfun_avoid_singularity\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/Desktop/2022/research/code/pykan/kan/utils.py\u001b[0m in \u001b[0;36mfit_params\u001b[0;34m(x, y, fun, a_range, b_range, grid_number, iteration, verbose, device)\u001b[0m\n\u001b[1;32m    235\u001b[0m         \u001b[0mb_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinspace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb_range\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_range\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msteps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mgrid_number\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    236\u001b[0m         \u001b[0ma_grid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_grid\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmeshgrid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindexing\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'ij'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 237\u001b[0;31m         \u001b[0mpost_fun\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma_grid\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb_grid\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    238\u001b[0m         \u001b[0mx_mean\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpost_fun\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeepdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    239\u001b[0m         \u001b[0my_mean\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeepdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "model.auto_symbolic()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "428571e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saving model version 0.5\n",
      "  function  fitting r2    r2 loss  complexity  complexity loss  total loss\n",
      "0        x    1.000000 -16.565706           1                1   -2.513141\n",
      "1      cos    1.000000 -16.599499           2                2   -1.719900\n",
      "2      sin    1.000000 -16.599499           2                2   -1.719900\n",
      "3      exp    0.999997 -16.268112           2                2   -1.653622\n",
      "4    x^0.5    0.999977 -14.896568           2                2   -1.379314\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('x',\n",
       " (<function kan.utils.<lambda>(x)>,\n",
       "  <function kan.utils.<lambda>(x)>,\n",
       "  1,\n",
       "  <function kan.utils.<lambda>(x, y_th)>),\n",
       " 0.9999996907837526,\n",
       " 1)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.unfix_symbolic(0,0,0)\n",
    "model.suggest_symbolic(0,0,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "0dea7189",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saving model version 0.4\n",
      "  function  fitting r2   r2 loss  complexity  complexity loss  total loss\n",
      "0        0    0.000000  0.000014           0                0    0.000003\n",
      "1      cos    0.969503 -5.034727           2                2    0.593055\n",
      "2      x^2    0.969092 -5.015413           2                2    0.596917\n",
      "3      sin    0.965249 -4.846400           2                2    0.630720\n",
      "4        x    0.000392 -0.000551           1                1    0.799890\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('0',\n",
       " (<function kan.utils.<lambda>(x)>,\n",
       "  <function kan.utils.<lambda>(x)>,\n",
       "  0,\n",
       "  <function kan.utils.<lambda>(x, y_th)>),\n",
       " 0.0,\n",
       " 0)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.unfix_symbolic(0,1,0)\n",
    "model.suggest_symbolic(0,1,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "ef60542b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARwAAAESCAYAAAAv/mqQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAlkElEQVR4nO3de1xUdf4/8BcXAS8wpshNEchWtKjAYVVQ1DTH0HW77UNaW9HS/cZ+KyW6rGRfU3ID22KpLTFL7edX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GBCAwMlGXdUVFRCAkJgdFoRFxcHIAb5+iFhYVYuXKlLNsEhO9TQkICTCYTvvrqK4wePRoA8K9//QsmkwmJiYmCt9fY2IiamhqrUFWCj48P9Ho9jEYjHnzwQcv7RqMR999/v91lEhIS8Omnn1q9t3v3bsTHx6NXL/XnCRezT/aUl5cr/n1IRbLviOsSsxM6efIkKy8vZ8uXL2f9+vVj5eXlrLy8nDU1NVnaREdHs+3bt1v+Oycnh+l0OrZ9+3Z2+PBh9tvf/tbpbovfddddrKSkhJWUlLA777zT5rb4zfvU1NTEnn32WVZcXMxOnDjB9u7dyxISEtjgwYNV2aeOW8hr165llZWVLD09nfXt25dVVVUxxhhbvHgxmzNnjqV9xy3XZ555hlVWVrK1a9c67W1xofv0l7/8he3YsYP98MMP7Ntvv2WLFy9mANi2bdvU2gUrTU1Nlt8KAJabm8vKy8stt/nl+o40Hzhz585lAGxee/futbQBwNavX2/57/b2dvbyyy+zkJAQ5uvryyZMmMAOHz6sfPFdaGxsZI8++ijz9/dn/v7+7NFHH7W5vXrzPl25coUZDAY2aNAg1qtXLzZ06FA2d+5cVl1drXzxP3vnnXdYREQE8/HxYaNGjWKFhYWW/2/u3Lls4sSJVu337dvH4uLimI+PD4uMjGT5+fkKV9wznn1auXIlGzZsGPPz82O33HILGz9+PNu5c6cKVdvXcdu+82vu3LmMMfm+IxoPhxCiGLe7LU4IUQ8FDiFEMRQ4hBDFUOAQQhRDgUMIUQwFDiFEMRQ4hBDFUOAQQhRDgUMIUQwFDiFEMRQ4hBDF/B+K/2VJMJWQCAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 300x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x, y = model.get_fun(0,1,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "id": "8f77c061",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "checkpoint directory created: ./model\n",
      "saving model version 0.0\n",
      "saving model version 0.1\n"
     ]
    }
   ],
   "source": [
    "from kan.utils import create_dataset_from_data\n",
    "\n",
    "dataset2 = create_dataset_from_data(x[:,None], y[:,None])\n",
    "model2 = KAN(width=[1,1,1])\n",
    "model2.fix_symbolic(0,0,0,'x^2',fit_params_bool=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "1c62302d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAAFICAYAAACcDrP3AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAf/ElEQVR4nO3de3DU9b3/8ddnc93cCIkRaxEkMaiAWOWmAioVEiQ9g0LH29GWDnUocqmMU88ZqUcOqBRHJUGOhxZrBWobe4zKIBzglKtcLBQELT8ugRytCaAI2TSXJQnZz++PL8kJEGKUb7Kb3edjhmFnv9ndd2ZIXrw/t6+x1loBAOAiT7ALAACEH8IFAOA6wgUA4DrCBQDgOsIFAOA6wgUA4DrCBQDgOsIFAOA6wgUA4DrCBQDgOsIFAOA6wgUA4DrCBQDgOsIFAOA6wgUA4LroYBcAdAbWWp08eVJVVVVKSkpSenq6jDHBLgsIWXQuQCt8Pp8KCgqUnZ2tjIwM9erVSxkZGcrOzlZBQYF8Pl+wSwRCkuFOlEDL1qxZo/Hjx6umpkaS0700auxaEhISVFRUpNzc3KDUCIQqwgVowZo1a5SXlydrrQKBwEW/zuPxyBijlStXEjBAM4QLcB6fz6fu3bvL7/e3GiyNPB6PvF6vSktLlZqa2v4FAp0Acy7AeZYsWaKampo2BYskBQIB1dTUaOnSpe1cGdB50LkAzVhrlZ2drZKSEn2THw1jjDIzM1VcXMwqMkCEC3COr776ShkZGZf0+vT0dBcrAjonhsWAZqqqqi7p9ZWVlS5VAnRuhAvQTFJS0iW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5lr8bfwOmOMsrKylJaW1t4lAp0C4QI0Y4zRtGnTvtVrp0+fzmQ+cBarxYDzXGyfy8WwzwW4EJ0LcJ7U1FQVFRXJGCOPp/UfEY/HI2OM3nnnHYIFaIZwAVqQm5urlStXyuv1yhhzwXBX43Ner1erVq1STk5OkCoFQhPhAlxEbm6uSktLlZ+fr8zMzHOuZWZmKj8/X2VlZQQL0ALmXIA2sNbq1KlTqqysVHJystLS0pi8B1pBuAAAXMewGADAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1hAsAwHWECwDAdYQLAMB1/x+on2d72IR9zAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 500x400 with 5 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model2.get_act(dataset2)\n",
    "model2.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "096134b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "| train_loss: 3.77e-04 | test_loss: 3.76e-04 | reg: 3.35e+00 | : 100%|█| 50/50 [00:46<00:00,  1.07it"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saving model version 0.2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "model2.fit(dataset2, steps=50);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "035e00f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "| train_loss: 3.73e-04 | test_loss: 3.72e-04 | reg: 3.35e+00 | : 100%|█| 50/50 [00:13<00:00,  3.81it"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "saving model version 0.3\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "model2.fit(dataset2, steps=50, update_grid=False);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "b65775e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAAFICAYAAACcDrP3AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAex0lEQVR4nO3de3CU9b3H8c+zWUg2JBAIAUTEsjEqFzkqVwWqFCWUeKYIY/FoFRwckSJWxvZ4vIMXLCpjgvbM6QnaAuMxWGIPRaixpRYKqKFcOyiXELUmXETIYi6b6/7OH0+SEyDESJ7wbHbfrxmGTJaFb2YIb36/52YZY4wAAHCQx+0BAACRh7gAABxHXAAAjiMuAADHERcAgOOICwDAccQFAOA44gIAcBxxAQA4jrgAABxHXAAAjiMuAADHERcAgOOICwDAccQFAOA4r9sDAB2BMUYnTpxQWVmZEhISlJycLMuy3B4LCFusXIAWBAIBZWVlKS0tTSkpKRowYIBSUlKUlpamrKwsBQIBt0cEwpLFkyiB5uXl5WnatGmqqKiQZK9eGjSsWuLj45Wbm6v09HRXZgTCFXEBmpGXl6eMjAwZYxQKhc756zwejyzL0rp16wgM0ARxAc4QCATUr18/BYPBFsPSwOPxyOfzqaioSElJSe0/INABcMwFOMPy5ctVUVHRqrBIUigUUkVFhVasWNHOkwEdBysXoAljjNLS0lRYWKjv8q1hWZb8fr8OHjzIWWSAiAtwmq+//lopKSlten9ycrKDEwEdE9tiQBNlZWVten9paalDkwAdG3EBmkhISGjT+xMTEx2aBOjYiAvQRHJyslJTU7/zcRPLspSamqoePXq002RAx0JcgCYsy9K8efPO670PPvggB/OBehzQB87AdS5A27FyAc6QlJSk3NxcWZYlj6flb5GGK/TfeecdwgI0QVyAZqSnp2vdunXy+XyyLOus7a6Gz/l8Pq1fv14TJ050aVIgPBEX4Bz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gIAcBxxAQA4jrgAABxHXAAAjiMuAADHERcAgOOICwDAccQFAOA44gIAcBxxAQA4jrgAABxHXAAAjiMuAADHERcAgOOICwDAccQFaAVjjEpKSmQk+2eeDg60iLgALQgEAsrKylJaWpom3HSTjDGacNNNSktLU1ZWlgKBgNsjAmHJMvwXDGhWXl6epk2bpoqKCknS1cbo75KGS9pV/5jj+Ph45ebmKj093b1BgTDEygVoRl5enjIyMhQMBmWMOWsbrOFzwWBQGRkZysvLc2lSIDyxcgHOEAgE1K9fPwWDQYVCocbPXyM1rlx2Nvn1Ho9HPp9PRUVFSkpKurDDAmGKlQtwhuXLl6uiouK0sLQkFAqpoqJCK1asaOfJgI6DlQvQhDFGaWlpKiwsPGsr7FwrF0myLEt+v18HDx6UVX88BohmrFyAJk6cOKFDhw5951ONjTE6dOiQTp482U6TAR0LcQGaKCsra9P7S0tLHZoE6NiIC9BEQkLCOV/bJ3tLbF8L709MTHR6JKBDIi5AE8nJyUpNTW32uElQ9rGWYDPvsyxLqamp6tGjR3uPCHQIxAVowrIszZs377ze++CDD3IwH6jH2WLAGc51ncu5cJ0LcDZWLsAZkpKSlJubK8uy5PG0/C3i8XhkWZbeeecdwgI0QVyAZqSnp2vdunXy+XyyLOus7a6Gz/l8Pq1fv14TJ050aVIgPBEX4BzS09NVVFSkzMxM+f3+017z+/3KzMxUcXExYQGawTEXoBWMMTp58qRKS0uVmJioHj16cPAeaAFxAQA4jm0xAIDjiAsAwHHEBQDgOOICAHAccQEAOI64AAAcR1wAAI4jLgAAxxEXAIDjiAsAwHHEBQDgOOICAHAccQEAOI64AAAc939v8OqzRcmF5gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 500x400 with 5 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model2.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "6cd26af5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    function  fitting r2    r2 loss  complexity  complexity loss  total loss\n",
      "0      x^0.5    0.999957 -14.193489           2                2   -1.238698\n",
      "1       sqrt    0.999957 -14.193489           2                2   -1.238698\n",
      "2        log    0.999722 -11.763921           2                2   -0.752784\n",
      "3    1/x^0.5    0.999485 -10.894391           2                2   -0.578878\n",
      "4  1/sqrt(x)    0.999485 -10.894391           2                2   -0.578878\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('x^0.5',\n",
       " (<function kan.utils.<lambda>(x)>,\n",
       "  <function kan.utils.<lambda>(x)>,\n",
       "  2,\n",
       "  <function kan.utils.<lambda>(x, y_th)>),\n",
       " 0.9999566254728288,\n",
       " 2)"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model2.suggest_symbolic(1,0,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "daabd91a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Best value at boundary.\n",
      "r2 is 0.9989821969546337\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(tensor([-9.8000,  9.8868, -0.3482,  1.2049]), tensor(0.9990))"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from kan.utils import fit_params\n",
    "fit_params(x**2, y, lambda x: x**(1/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "8dc20f20",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "skipping (0,0,0) since already symbolic\n",
      "fixing (1,0,0) with x^0.5, r2=0.9999494098870415, c=2\n",
      "saving model version 0.4\n"
     ]
    }
   ],
   "source": [
    "model2.auto_symbolic()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "f27f3daa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle 1.19 - 1.08 \\sqrt{1 - 1.0 x_{1}^{2}}$"
      ],
      "text/plain": [
       "1.19 - 1.08*sqrt(1 - 1.0*x_1**2)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from kan.utils import ex_round\n",
    "ex_round(model2.symbolic_formula()[0][0], 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a61540c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
